//
//  UITableViewCell+HDMessageCell.m
//  app
//
//  Created by D on 15/5/26.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDMessageCell.h"

static const CGFloat kMargin = 24.0f;
static const CGFloat kFaceH = 88.0f;
static const CGFloat kFlowerH = 60.0f;
static const CGFloat kshopImageH = 152.0f;
static const CGFloat kshopNameW = 180.0f;
static const CGFloat kshopNameH = 100.0f;
static const CGFloat kshopPriceW = 80.0f;
static const CGFloat kshopPriceH = 60.0f;
static const CGFloat kContentW = 320.0f;
static int i = 0;

@interface HDMessageCell ()

@property (nonatomic,strong) NSMutableArray * highPictureArrs;


@end

#pragma mark - add by sn
@interface  HDMessageCell ()
@property (nonatomic, copy) NSString * imgUrl;
@property (nonatomic, copy) NSString * heiImgUrl;
@end
#pragma mark - add end

@implementation  HDMessageCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier uid:(NSString*)uid view:(UIView*)view  scaleArrs:(NSMutableArray*)scalerArr highPictureArr:(NSMutableArray*)highPictureArr
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.uid = uid;
        self.scaleImages = scalerArr;
        self.highPictureArrs = highPictureArr;
        self.picFahterView = view;
    }
    return self;
}
+ (float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
    UITextView *detailTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, width, 0)];
    detailTextView.font = [UIFont systemFontOfSize:fontSize];
    detailTextView.text = value;
    CGSize deSize = [detailTextView sizeThatFits:CGSizeMake(width,CGFLOAT_MAX)];
    return deSize.height;
}


-(void)cellWithModel:(HDMessageModel *)model otherFace:(NSString *)face rowNumber:(NSInteger)row
{
    
//    DLog(@"wight = %f,hight = %f",model.textWight,model.textHeight);
    self.frame = CGRectMake(0, 0, UBO_SCREEN.width, UF(self.Hight*2+56));
    
    if (model.textHeight < 20) {
        self.Hight = kFaceH/2;
    }else{
        self.Hight = model.textHeight+20;
    }
    
    if (model.textWight < 50) {
        self.Wight = 70.0f;
    }else{
        self.Wight = model.textWight;
    }
    
    
    if (self.uid.integerValue == model.uid.integerValue) {
        
        UIImage * BGimage = [UIImage imageNamed:@"chat_me.png"];
//        CGFloat top = UP(76);
//        CGFloat bottom = UP(10);
//        CGFloat left = UP(54);
//        CGFloat right = UP(54);
        CGFloat top = 38;
        CGFloat bottom = 5;
        CGFloat left = 27;
        CGFloat right = 27;
        UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
        BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
        
        
        self.face = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-kMargin/2-kFaceH/2 fy:UB_1_2 oy:-kFaceH/4 ], [self.ubo ow:kFaceH/2 oh:kFaceH/2])];
        
        if ([[NSUserDefaults standardUserDefaults]objectForKey:@"headImage"]) {
            [self.face setImage:[UIImage imageWithData:[[NSUserDefaults standardUserDefaults]objectForKey:@"headImage"]]];
        }else
        {
            if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:@"user_Head"]) {
                
                [self.face setImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:@"user_Head"]];
            }else{
                
                if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"face"]length] > 1) {
                    [self.face sd_setImageWithURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"face"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        
                        NSLog(@"图片加载完成后做的事情");
                        NSData * data = UIImageJPEGRepresentation(image,1.0);
                        [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:@"user_Head" toDisk:YES];
                        
                        
                    }];
                }else
                {
                    
                    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"gender"]integerValue] == 1) {
                        [self.face setImage:[UIImage imageNamed:@"isboy"]];
                    }else
                    {
                        [self.face setImage:[UIImage imageNamed:@"isgirl"]];
                    }
                    
                }
                
                
            }
        }
        
        self.face.layer.masksToBounds = YES;
        self.face.layer.cornerRadius = UF(10);
        [self.contentView addSubview:self.face];
        
        
        if (model.picture.length != 0) {
           
                self.Hight = 120.0f;
                self.Wight = 90.0f;


            self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:0 ox:-kMargin/2-self.Wight-kMargin fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight+kMargin oh:self.Hight+12])];
            [self.backImage setImage:BGimage];
            [self.contentView addSubview:self.backImage];
            
            UIView * picFatherView = [[UIView alloc]initWithFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin/4 fy:UB_1_2 oy:-self.Hight/2], [self.ubo ow:self.Wight oh:self.Hight])];
            picFatherView.userInteractionEnabled = YES;
            [self.contentView addSubview:picFatherView];
            
            HDPictureButton * picture = [[HDPictureButton alloc]initWithFrame:CGRectOf([picFatherView.ubo fx:0  fy:0 ], [self.ubo ow:self.Wight oh:self.Hight])];
   
            picture.layer.masksToBounds = YES;
            picture.layer.cornerRadius = UF(12);

            if (model.type.integerValue == 2) {
                
                #pragma mark - add by sn
                self.imgUrl = model.picture;
                #pragma mark - add end
                
                NSString * headKey = [NSString stringWithFormat:@"%@",model.msgid];
                if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey]) {
                    
                    [picture setBackgroundImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey] forState:UIControlStateNormal];
                }else
                {
                    [picture sd_setBackgroundImageWithURL:[NSURL URLWithString:model.picture] forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        NSData * data = UIImageJPEGRepresentation(image,1.0);
                        
                        [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:headKey toDisk:YES];
                    }];
                    
                    
                }
                
            }else{
                NSData * data = [NSData dataWithContentsOfFile:model.picture];
                [picture setBackgroundImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
                
            }

            if ([model.picture rangeOfString:@"http"].location !=NSNotFound) {

                NSString * str = [model.picture stringByReplacingOccurrencesOfString:@"_\\w{2}\\d{3}" withString:@""options:NSRegularExpressionSearch range:NSMakeRange(0, model.picture.length)];
                
                #pragma mark - add by sn
                self.heiImgUrl = str;
                #pragma mark - add end
                
                picture.tag = row;
                [picture addTarget:self action:@selector(topPicture:) forControlEvents:UIControlEventTouchUpInside];
                
                
                HDPictureButton * btn = [[HDPictureButton alloc]init];
                [btn setBackgroundImage:picture.imageView.image forState:UIControlStateNormal];
                btn.tag = row;
                __block BOOL isInclude = NO;
                
                [self.picFahterView.subviews enumerateObjectsUsingBlock:^(HDPictureButton * obj, NSUInteger idx, BOOL *stop) {
                    
                    if (obj.tag == btn.tag) {
                        isInclude = YES;
                        return ;
                    }
                    
                }];
                
                if (isInclude == NO) {
                    [self.picFahterView addSubview:btn];
                    [self.scaleImages addObject:model.picture];
                    [self.highPictureArrs addObject:str];
                }
                
              
            }
            
           
            [picFatherView addSubview:picture];
   
            
            self.failure = [[HDFailureButton alloc]initWithFrame:CGRectOf([self.backImage.ufo ox:-kMargin/4-kFlowerH/2 fy:UB_1_2 oy:-kFlowerH/4], [self.ubo ow:kFlowerH/2 oh:kFlowerH/2])];
            [self.failure setBackgroundImage:[UIImage imageNamed:@"failure.png"] forState:UIControlStateNormal];
            self.failure.tag = model.msgid.integerValue;
            self.failure.isPicture = YES;
            [self.failure addTarget:self action:@selector(againSendMessage:) forControlEvents:UIControlEventTouchUpInside];
            self.failure.titleLabel.text = model.time;
            //        [self.failure setHidden:YES];
            [self.contentView addSubview:self.failure];
            
            
        }else
        {
            if (model.myType.integerValue == 3)
            {
                //商品内容
                self.Wight = [self.ubo fw:UB_WIDTH uw:-(24*4+88*2)];
                self.Hight = 100.0f;
                
//                DLog(@"%@",model.extends);
                
                self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:0  ox:-self.Wight-kMargin/2 fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight oh:self.Hight ])];
                [self.backImage setImage:BGimage];
                [self.contentView addSubview:self.backImage];
                
                //商品图片
                UIImageView * shopImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin/4  fy:UB_1_2 oy:-kshopImageH/4], [self.ubo ow:kshopImageH/2 oh:kshopImageH/2])];
                shopImage.layer.masksToBounds = YES;
                shopImage.layer.cornerRadius = UF(10);
                shopImage.layer.borderWidth = 0.5;
                shopImage.layer.borderColor = [UIColor grayColor].CGColor;
                [shopImage sd_setImageWithURL:[NSURL URLWithString:[model.extends objectForKey:@"title_pic"]]];
                [self.contentView addSubview:shopImage];
                
                //商品名称
                UILabel * shopName = [[UILabel alloc]initWithFrame:CGRectOf([shopImage.ufo fx:1 ox:kMargin/8 fy:0 oy:-kMargin/4 ], [self.ubo ow:kshopNameW/2 oh:kshopNameH/2])];
                shopName.lineBreakMode = NSLineBreakByCharWrapping;
                shopName.numberOfLines = 2;
                [shopName setFont:JKAppGlobleFontMinTagText];
                [shopName setTextColor:[UIColor blackColor]];
                shopName.text = model.extends[@"title"];
                [self.contentView addSubview:shopName];
                
                //康喜汇
                UILabel * kangxihui = [[UILabel alloc]initWithFrame:CGRectOf([shopImage.ufo fx:1 ox:kMargin/8 fy:1 oy:-kshopPriceH/2], [self.ubo ow:kshopPriceW/2 oh:kshopPriceH/2])];
                kangxihui.text = @"价格:";
                [kangxihui setFont:JKAppGlobleFontContentText];
                [kangxihui setTextColor:[UIColor whiteColor]];
                [self.contentView addSubview:kangxihui];
                
                //商品价格
                UILabel * shopPrice = [[UILabel alloc]initWithFrame:CGRectOf([kangxihui.ufo fx:1 fy:UB_1_2 oy:-kshopPriceH/4], [self.ubo ow:kshopNameW/4 oh:kshopPriceH/2])];
                shopPrice.text = [NSString stringWithFormat:@"%@",model.extends[@"sale_price"]];
//                shopPrice.text = model.extends[@"sale_price"];
                [shopPrice setFont:JKAppGlobleFontContentText];
                [shopPrice setTextColor:[UIColor redColor]];
                [self.contentView addSubview:shopPrice];
            }else
            {
                self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:0 ox:-kMargin/2-self.Wight-kMargin fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight+kMargin oh:self.Hight])];
                [self.backImage setImage:BGimage];
                [self.contentView addSubview:self.backImage];
                
                
                self.content = [[HDMsgLable alloc]initFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin/4 fy:UB_1_2 oy:-self.Hight/2], [self.ubo ow:self.Wight oh:self.Hight])];
                self.content.layer.masksToBounds = YES;
                self.content.layer.cornerRadius = UF(10);
                self.content.text = model.content;
                self.content.lineBreakMode = NSLineBreakByCharWrapping;
                self.content.numberOfLines = 0;
                [self.content setTextAlignment:NSTextAlignmentCenter];
                self.content.backgroundColor = [UIColor clearColor];
                self.content.font = JKAppGlobleFontContentText;
                [self.contentView addSubview:self.content];
                
                self.failure = [[HDFailureButton alloc]initWithFrame:CGRectOf([self.backImage.ufo ox:-kMargin/4-kFlowerH/2 fy:UB_1_2 oy:-kFlowerH/4], [self.ubo ow:kFlowerH/2 oh:kFlowerH/2])];
                [self.failure setBackgroundImage:[UIImage imageNamed:@"failure.png"] forState:UIControlStateNormal];
                self.failure.tag = model.msgid.integerValue;
                self.failure.isPicture = NO;
                [self.failure addTarget:self action:@selector(againSendMessage:) forControlEvents:UIControlEventTouchUpInside];
                self.failure.titleLabel.text = model.content;
                //        [self.failure setHidden:YES];
                [self.contentView addSubview:self.failure];
            }

        }

        self.flower = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        self.flower.frame = CGRectOf([self.backImage.ufo ox:-kMargin/4-kFlowerH/2 fy:UB_1_2 oy:-kFlowerH/4], [self.ubo ow:kFlowerH/2 oh:kFlowerH/2]);
        self.flower.tag = row;
//        [self.flower setHidden:YES];
        [self.contentView addSubview:self.flower];
        
        
        
        
        if (model.flower.integerValue == 111) {
            [self.flower setHidden:NO];
            [self.flower startAnimating];
        }else
        {
            [self.flower setHidden:YES];
            [self.flower stopAnimating];
        }
        
        if (model.red.integerValue == 111) {
            [self.failure setHidden:NO];
            
        }else
        {
            [self.failure setHidden:YES];
        }
        
        
    }else
    {
        
        UIImage * BGimage = [UIImage imageNamed:@"chat_you.png"];
//        CGFloat top = UP(70);
//        CGFloat bottom = UP(16);
//        CGFloat left = UP(40);
//        CGFloat right = UP(16);
        CGFloat top = 35;
        CGFloat bottom = 8;
        CGFloat left = 20;
        CGFloat right = 8;
        
        UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
        BGimage = [BGimage resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
        
        self.face = [[UIImageView alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin/2 fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:kFaceH/2 oh:kFaceH/2])];
        NSString * headKey = [NSString stringWithFormat:@"%@",model.pmid];
        if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey]) {
            
            [self.face setImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey]];
        }else
        {
            [self.face sd_setImageWithURL:[NSURL URLWithString:face] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
                NSData * data = UIImageJPEGRepresentation(image,1.0);
                [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:headKey toDisk:YES];
            }];
        }
        self.face.layer.masksToBounds = YES;
        self.face.layer.cornerRadius = UF(10);
        [self.contentView addSubview:self.face];
        
        
        if (model.picture.length != 0) {
            self.Hight = 120.0f;
            self.Wight = 90.0f;
           


            self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:1 ox:kMargin/2 fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight+kMargin oh:self.Hight+12])];
            [self.backImage setImage:BGimage];
            [self.contentView addSubview:self.backImage];
            
            UIView * picFatherView = [[UIView alloc]initWithFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin/4 fy:UB_1_2 oy:-self.Hight/2], [self.ubo ow:self.Wight oh:self.Hight])];
            picFatherView.userInteractionEnabled = YES;
            [self.contentView addSubview:picFatherView];
            
           HDPictureButton *picture = [[HDPictureButton alloc]initWithFrame:CGRectOf([picFatherView.ubo fx:0  fy:0 ], [self.ubo ow:self.Wight oh:self.Hight])];
            picture.layer.masksToBounds = YES;
            picture.layer.cornerRadius = UF(12);
            if (model.type.integerValue == 2) {
                
                #pragma mark - add by sn
                self.imgUrl = model.picture;
                #pragma mark - add end
                
                NSString * headKey = [NSString stringWithFormat:@"%@",model.msgid];
                if ([[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey]) {
                    
                    [picture setBackgroundImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:headKey] forState:UIControlStateNormal];
                }else
                {
                    [picture sd_setBackgroundImageWithURL:[NSURL URLWithString:model.picture] forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        NSData * data = UIImageJPEGRepresentation(image,1.0);
                        
                        [[SDImageCache sharedImageCache] storeImage:image recalculateFromImage:YES imageData:data forKey:headKey toDisk:YES];
                    }];
                    
                    
                }
                
            }else{
                NSData * data = [NSData dataWithContentsOfFile:model.picture];
                [picture setBackgroundImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
                
            }
            if ([model.picture rangeOfString:@"http"].location !=NSNotFound) {
                
                
                
                NSString * str = [model.picture stringByReplacingOccurrencesOfString:@"_\\w{2}\\d{3}" withString:@""options:NSRegularExpressionSearch range:NSMakeRange(0, model.picture.length)];
                
                #pragma mark - add by sn
                self.heiImgUrl = str;
                #pragma mark - add end
                
                picture.tag = i++;
                [picture addTarget:self action:@selector(topPicture:) forControlEvents:UIControlEventTouchUpInside];
                
                
                HDPictureButton * btn = [[HDPictureButton alloc]init];
                [btn setBackgroundImage:picture.imageView.image forState:UIControlStateNormal];
                btn.tag = row;
                BOOL isInclude = NO;
                for (HDPictureButton * b in self.picFahterView.subviews) {
                    if (b.tag == btn.tag) {
                        isInclude = YES;
                        return;
                    }
                }
                if (isInclude == NO) {
                    [self.picFahterView addSubview:btn];
                    [self.scaleImages addObject:model.picture];
                    [self.highPictureArrs addObject:str];
                }
                
                
                
            }
            
            
            [picFatherView addSubview:picture];

            
            
            
            
            
            
        }else
        {
            //非图片内容
            if (model.myType.integerValue == 3) {
                //商品内容
                self.Wight = [self.ubo fw:UB_WIDTH uw:-(24*4+88*2)];
                self.Hight = 100.0f;
                
                self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:1 ox:kMargin/2 fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight oh:self.Hight])];
                [self.backImage setImage:BGimage];
                [self.contentView addSubview:self.backImage];
                
                //商品图片
                UIImageView * shopImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin fy:UB_1_2 oy:-kshopImageH/4], [self.ubo ow:kshopImageH/2 oh:kshopImageH/2])];
                shopImage.layer.masksToBounds = YES;
                shopImage.layer.cornerRadius = UF(10);
                shopImage.layer.borderWidth = 0.5;
                shopImage.layer.borderColor = [UIColor grayColor].CGColor;
                [shopImage sd_setImageWithURL:[NSURL URLWithString:[model.extends objectForKey:@"title_pic"]]];
                [self.contentView addSubview:shopImage];
                
                //商品名称
                UILabel * shopName = [[UILabel alloc]initWithFrame:CGRectOf([shopImage.ufo fx:1 ox:kMargin/8 fy:0 oy:-kMargin/4 ], [self.ubo ow:kshopNameW/2 oh:kshopNameH/2])];
                shopName.lineBreakMode = NSLineBreakByCharWrapping;
                shopName.numberOfLines = 2;
                [shopName setFont:JKAppGlobleFontMinTagText];
                [shopName setTextColor:[UIColor blackColor]];
                shopName.text = model.extends[@"title"];
                [self.contentView addSubview:shopName];
                
                //康喜汇
                UILabel * kangxihui = [[UILabel alloc]initWithFrame:CGRectOf([shopImage.ufo fx:1 ox:kMargin/8 fy:1 oy:-kshopPriceH/2], [self.ubo ow:kshopPriceW/2 oh:kshopPriceH/2])];
                kangxihui.text = @"价格:";
                [kangxihui setFont:JKAppGlobleFontContentText];
                [kangxihui setTextColor:[UIColor blackColor]];
                [self.contentView addSubview:kangxihui];
                
                //商品价格
                UILabel * shopPrice = [[UILabel alloc]initWithFrame:CGRectOf([kangxihui.ufo fx:1 fy:UB_1_2 oy:-kshopPriceH/4], [self.ubo ow:kshopNameW/4 oh:kshopPriceH/2])];
                shopPrice.text = [NSString stringWithFormat:@"%@",model.extends[@"sale_price"]];
                [shopPrice setFont:JKAppGlobleFontContentText];
                [shopPrice setTextColor:[UIColor redColor]];
                [self.contentView addSubview:shopPrice];
                
                
                
                
                
            }else
            {
                //文字内容
                self.backImage = [[UIImageView alloc]initWithFrame:CGRectOf([self.face.ufo fx:1 ox:kMargin/2 fy:UB_1_2 oy:-kFaceH/4], [self.ubo ow:self.Wight+kMargin oh:self.Hight])];
                [self.backImage setImage:BGimage];
                [self.contentView addSubview:self.backImage];
                
                self.content = [[HDMsgLable alloc]initFrame:CGRectOf([self.backImage.ufo fx:0 ox:kMargin*3/4 fy:UB_1_2 oy:-self.Hight/2], [self.ubo ow:self.Wight oh:self.Hight])];
                self.content.userInteractionEnabled = YES;
                self.content.layer.masksToBounds = YES;
                self.content.layer.cornerRadius = UF(10);
                self.content.text = model.content;
                self.content.lineBreakMode = NSLineBreakByCharWrapping;
                self.content.numberOfLines = 0;
                //            self.content;
                [self.content setTextAlignment:NSTextAlignmentCenter];
                self.content.backgroundColor = [UIColor clearColor];
                self.content.font = JKAppGlobleFontContentText;
                [self.contentView addSubview:self.content];
            }
        }

    }

    HDAppDelegate *appDelegate = (HDAppDelegate *)[UIApplication sharedApplication].delegate;
    self.frame = CGRectMake(0, 0, UBO_SCREEN.width, self.Hight+28);

    
}



-(void)flower:(NSNotification*)info
{
    NSDictionary * flowerDic = [info userInfo];
    [self isHidenFlowerOrButtonWithState:[flowerDic objectForKey:@"state"] ActivityView:self.flower Button:self.failure];
    
}

-(void)isHidenFlowerOrButtonWithState:(NSString*)state ActivityView:(UIActivityIndicatorView*)flower Button:(UIButton*)failBtn
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(flowerShowWithState:ActivityView:Button:)]) {
        [self.delegate flowerShowWithState:state ActivityView:flower Button:failBtn];
    }
    
}

-(void)againSendMessage:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(againSendMessage:ActivityView:)]) {
        [self.delegate againSendMessage:sender ActivityView:self.flower];
    }
}


-(void)topPicture:(HDPictureButton*)sender
{
    SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
    browser.sourceImagesContainerView = self.picFahterView; // 原图的父控件
//    browser.imageCount = self.scaleImages.count; // 图片总数
    browser.imageCount = 1;
//    browser.currentImageIndex = sender.tag ;
    browser.currentImageIndex = 0;
    
//    if (browser.imageCount == browser.currentImageIndex) {
//        browser.currentImageIndex = sender.tag - 1;
//    }
    
    browser.delegate = self;
    [browser show];
}
#pragma mark - photobrowser代理方法

// 返回临时占位图片（即原来的小图）
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
  
//    UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: self.scaleImages[index]]]];
    UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: self.imgUrl]]];
    return image;

}


// 返回高质量图片的url
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
{
    return [NSURL URLWithString:self.heiImgUrl];
//    return self.highPictureArrs[index];
}

@end




